import os
from rich import print
import yaml

from utils import parse_argv_by_key

CONFIG_NAME = "config.yml"
configData = None
def get_config():
    global configData
    global CONFIG_NAME
    if configData is not None:
        return configData
    config_path = os.path.join(os.getcwd(), CONFIG_NAME)
    ccpath = parse_argv_by_key('c',None)
    if ccpath:
        config_path = ccpath+'.yml'

    print(f'[blue]使用配置文件:{config_path}')
    try:
       with open(config_path,'r',encoding='utf-8') as file:
           configData = yaml.safe_load(file)
    except FileNotFoundError as e:
        print(e)
        raise e
    except Exception as e:
        print(e)
        raise ValueError(f"配置文件:{config_path} 没找到")
    return configData

